$(function () {

	var phoneList = ['15005058589', '18046057263', "18506927812", "18650051425"]
	var cooperationList = [{
		name: '颜经理',
		phone: 15005058589,
	}, {
		name: '叶经理',
		phone: 18650051425,
	}, {
		name: '彭经理',
		phone: 18506927812,
	}, {
		name: '林经理',
		phone: 18046057263,
	}]

	function randomsort(a, b) {
		return Math.random() > .5 ? -1 : 1;
	}
	phoneList = phoneList.sort(randomsort)
	cooperationList = cooperationList.sort(randomsort)
	cooperationList.forEach((item) => {
		$('#cooperationList').append(`<p><a href="tel:${item.phone}" class="a-href">${item.phone}（${item.name}）</a></p>`)
	})
	$('.randomPhone').attr('href', 'tel:' + phoneList[0])
	$('body').append(
		`<div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1">
        <div class="am-modal-dialog" >
            <div class="am-modal-hd modal-title">获取免费体验资格
                <a href="javascript: void(0)" class="am-close  modal-close" data-am-modal-close></a>
            </div>
            <div class="am-modal-bd modal-body">
                <form action="" class="am-form">
					<div class="am-form-group"><label><span class="red-xing">*</span>电话：</label><input id='phones' type="number" placeholder="请填写您的电话"  class="form-control"></div>
					<div class="am-form-group"><label><span class="red-xing">*</span>验证码：</label><br/><input type="number"  id="code1" placeholder="请输入您的验证码" class="form-control"><input type="button" class="send-code1" value="获取验证码"></input></div>
                </form>
            </div>
            <div class="modal-footer">
                <input type="submit" class="btn btn-primary btn-submit" onclick="apply()" value="提交">
            </div>
        </div>
    </div>`
	)


	var timer, time = 60

	$('.send-code1').click(function () {
		clearInterval(timer)
		if ($('#phones').val().match(
				/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/) ===
			null) {
			alert('请正确填写您的手机号码')
			return
		}
		$('.send-code1').attr('disabled', true)
		timer = setInterval(function () {
			time -= 1
			if (time === 0) {
				$('.send-code1').attr('disabled', false)
				time = 60
				$('.send-code1').val('重新获取')
				clearInterval(timer)
				return

			}
			$('.send-code1').val(time + 's后')

		}, 1000)
		$.ajax({
			url: 'https://proxfix.vmajy.com/api/apply/code',
			type: 'post',
			data: JSON.stringify({
				mobile: $('#phones').val(),
			}),
			dataType: "json",
			headers: {
				'Content-Type': 'application/json;charset=UTF-8'
			},
			success: function (data) {
				if (data.result_code == 0) {
					alert('您好，我们经理将尽快联系您，请留意福州号码。')
					$(".am-dimmer").click()
				} else {
					alert(data.result_msg)
					$(".am-dimmer").click()
				}
			}
		})
	})


	window.apply = function () {
	 if ($('#phones').val().match(/^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/) === null) {
			alert('请正确填写您的手机号码，方便我们与您联系')
			return
		} 

		$.ajax({
			url: 'https://proxfix.vmajy.com/api/apply/new/add',
			type: 'post',
			data: JSON.stringify({
				mobile: $('#phones').val(),
				projectName: '微码微控',
				machineType: 2,
				applyType: 2,
				platformId: 0,
				code: $('#code1').val()
			}),
			dataType: "json",
			headers: {
				'Content-Type': 'application/json;charset=UTF-8'
			},
			success: function (data) {
				if (data.result_code == 0) {
					alert('您好，我们经理将尽快联系您，请留意福州号码。')
					$(".am-dimmer").click()
				} else {
					alert(data.result_msg)
					$(".am-dimmer").click()
				}
			},
			error: function (err) {
				alert(err.responseJSON.err_msg)
			}
		})
	}

})

//设置转化属性
window._agl = window._agl || [];
(function () {
    _agl.push(
        ['production', '_f7L2XwGXjyszb4d1e2oxPybgD']
    );
    (function () {
        var agl = document.createElement('script');
        agl.type = 'text/javascript';
        agl.async = true;
        agl.src = 'https://fxgate.baidu.com/angelia/fcagl.js?production=_f7L2XwGXjyszb4d1e2oxPybgD';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(agl, s);
    })();
})();